package workflowminer.domain;

import java.util.Vector;

public class Role implements Comparable<Role> {
	
	private Vector<String> permissions = new Vector<String>();
	
	private Vector<Role> contributors = new Vector<Role>();
	
	private int count;
	
	public Role( Vector<String> perm){
		this.permissions = perm;
		this.contributors = new Vector<Role>();
		this.count=0;
	}

	public void setCount(int i) {
		this.count=i;
	}
	
	public Vector<String> getPermissions(){
		return this.permissions;
	}
	
	public Role getInterseccion(Role r)
	{
		Vector<String> perms = r.getPermissions();
		Role newRole= new Role(new Vector<String>());
		for (String permission : permissions) {
			if (perms.contains(permission)){
				newRole.addPermission(permission);
			}
		}
		return newRole;
	}

	private void addPermission(String permission) {
		if(!this.permissions.contains(permission)){
			this.permissions.add(permission);
		}
	}

	@Override
	public int compareTo(Role o) {
		return this.permissions.equals(o.getPermissions())? 0:1;
	}
	
	public boolean equals(Role o){
		return this.permissions.equals(o.getPermissions()); 
	}

	public int getCount() {
		return this.count;
	}
	
	public void addContributor(Role role){
		this.contributors.add(role);
	}
	
	public boolean isContributor(Role role){
		return this.contributors.contains(role);
	}
	
}
